/**
 * 适配器模式
 */

// 普通播放器接口
class MediaPlayer {}

MediaPlayer.prototype.play = (type) => {
  console.log(`改播放器播放功能只有Mp3`)
}

// 高级播放器接口
class AdvancedMediaPlayer {}

AdvancedMediaPlayer.prototype.playMp3 = () => {}

AdvancedMediaPlayer.prototype.playMp4 = () => {}

AdvancedMediaPlayer.prototype.playMp5 = () => {}

// 高级播放器接口实现
class AdvancedPlayer extends AdvancedMediaPlayer {
  constructor() {
    super()  
  }

  playMp3() {
    console.log(`播放Mp3`)  
  }

  playMp4() {
    console.log(`播放Mp4`)  
  }

  playMp5() {
    console.log(`播放Mp5`)  
  }

}

// 创建传统播放器的适配器
class MediaAdapter extends MediaPlayer {
  constructor() {
    super()
    this.advancedPlayer = new AdvancedPlayer()
  } 

  play(audioType) {
    switch(audioType) {
      case 'Mp3': 
        this.advancedPlayer.playMp3()
        break
      case 'Mp4':
        this.advancedPlayer.playMp4()
        break
      case 'Mp5':
        this.advancedPlayer.playMp5()
        break
      default:
        this.advancedPlayer.playMp3()
        break
    }  
  }
}

// 创建传统播放器的实现类
class AudioPlayer extends MediaPlayer {
  constructor() {
    super()
    this.player = new MediaAdapter()  
  }
  
  play(audioType) {
    this.player.play(audioType)  
  }
    
}

const audioPlayer = new AudioPlayer()

audioPlayer.play()
audioPlayer.play('Mp3')
audioPlayer.play('Mp4')
audioPlayer.play('Mp5')
